# Contributor: Jacek Pruciak <alpine@juniorjpdj.pl>
# Maintainer: Jacek Pruciak <alpine@juniorjpdj.pl>
pkgname=tcmu-runner
pkgver=1.6.0
pkgrel=5
pkgdesc="A daemon that handles the userspace side of the LIO TCM-User backstore."
url="https://github.com/open-iscsi/tcmu-runner"
arch="all !armhf !armv7 !x86" # blocked by ceph
license="Apache-2.0"
makedepends="cmake glib-dev kmod-dev libnl3-dev ceph-dev samurai"
options="!check" # no upstream tests
subpackages="libtcmu:libs libtcmu-dev $pkgname-doc $pkgname-rbd"
source="https://github.com/open-iscsi/tcmu-runner/archive/v$pkgver/tcmu-runner-$pkgver.tar.gz
	tcmu-runner-fix-i586-size_t-error.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-Dwith-glfs=false \
		-Dwith-tcmalloc=false \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

check() {
	# I asked upstream for tests, so let's leave it here. It's disabled anyway.
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

rbd() {
	amove usr/lib/tcmu-runner/handler_rbd.so
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	mkdir -p "$pkgdir"/usr/share/dbus-1/system.d/
	mv "$pkgdir"/etc/dbus-1/system.d/* "$pkgdir"/usr/share/dbus-1/system.d/
}

sha512sums="
dca6d64c7bf90567357afacb9f0ba19438029172756ef06d115164610899e8a6546dea683f4d0e2018cb911d1a895b93a25b7b1770fdaca975fdfc93b77e5e4b  tcmu-runner-1.6.0.tar.gz
a26fca68a73e5cc6726e880f5004b96fd0f5d3cbcaf6dd7a6a8a5e03f9089c91ec271b2517ea127b37dcead1499baac7cf6a5f23c0d4a70d13baa0107baefab3  tcmu-runner-fix-i586-size_t-error.patch
"
